package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.constant.HttpResultEnum;
import com.dongdongshop.data.DataResult;
import com.dongdongshop.pojo.seller.TbSeller;
import com.dongdongshop.service.seller.SellerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 商家表
 */
@Controller
@RequestMapping("sellerController")
public class SellerController {

    private final Logger log = LoggerFactory.getLogger(SellerController.class);

    @Reference
    private SellerService sellerService;

    @RequestMapping("seller") // 商家管理
    public String seller() {
        return "seller/seller";
    }

    @RequestMapping("getSellerData")
    @ResponseBody
    public DataResult getSellerData(String status, String name, String nickName){//商家数据查询
        List<TbSeller> sellers = null;
        try {
            sellers = sellerService.getSellerData(name,nickName,status);
        }catch (Exception e){
            log.error("根据公司名称或者店铺名称模糊查询未审核的商家信息异常",e);
            return new DataResult(HttpResultEnum.ERROR.getCode(),HttpResultEnum.ERROR.getMessage());
        }
        return new DataResult(HttpResultEnum.SUCCESS.getCode(),HttpResultEnum.SUCCESS.getMessage(),sellers);
    }
    @RequestMapping("getSellerDetailed")
    @ResponseBody
    public DataResult getSellerDetailed(String sellerId){//商家数据详细
        TbSeller tbSeller = null;
        try {
            tbSeller = sellerService.getSellerDetailed(sellerId);
        }catch (Exception e){
            log.error("商家数据详细:",e);
            return new DataResult(HttpResultEnum.ERROR.getCode(),HttpResultEnum.ERROR.getMessage());
        }
        return new DataResult(HttpResultEnum.SUCCESS.getCode(),HttpResultEnum.SUCCESS.getMessage(),tbSeller);
    }
    /*
    * 商家审核
    * */
    @RequestMapping("seller1")
    public String seller1(){
        return"seller/seller_1";
    }
    /*
    * 商家审核数据
    * */
    @RequestMapping("getSeller1Data")
    @ResponseBody
    public DataResult getSeller1Data(String name, String nickName){
        List<TbSeller> tbSellers = null;
        try {
            tbSellers = sellerService.getSeller1Data(name,nickName);
        }catch (Exception e){
            log.error("商家审核数据:",e);
            return new DataResult(HttpResultEnum.ERROR.getCode(),HttpResultEnum.ERROR.getMessage());
        }
        return new DataResult(HttpResultEnum.SUCCESS.getCode(),HttpResultEnum.SUCCESS.getMessage(),tbSellers);
    }
    /*
    * 商家审核状态
    * */
    @RequestMapping("updateStatus")//商家审核状态
    @ResponseBody
    public DataResult updateStatus(TbSeller tbSeller){
        try {
            sellerService.updateStatus(tbSeller);
        }catch (Exception e){
            log.error("商家审核状态:",e);
            return new DataResult(HttpResultEnum.ERROR.getCode(),HttpResultEnum.ERROR.getMessage());
        }
        return new DataResult(HttpResultEnum.SUCCESS.getCode(),HttpResultEnum.SUCCESS.getMessage());
    }
}